package demo.demo06;


public class Exceptions {
    public static void main(String[] args) {


        try {
            int a = 1;
            int b = 0;

            //Ctrl + Alt + T
            System.out.println(a / b);
        } catch (Exception e) {
            System.out.println("Exception");
            System.exit(1);//结束程序
            e.printStackTrace();//打印错误的栈信息
        } finally {
            System.out.println("finally");
        }
/*
        //假设要捕获异常要从小到大
        try {//监控区域
            System.out.println(a / b);
        } catch (Exception e) {  //（想要捕获的异常类型）
            System.out.println("Exception");
        } catch (Error E) {
            System.out.println("Error");
        } catch (Throwable t) {
            System.out.println("Throwable");
        } finally {//处理善后工作无论如何都会执行的
            System.out.println("finally");
        }*/
    }

    //在方法中抛出异常
    public void test(int a, int b) throws ArithmeticException {
        if (b == 0) {
            throw new ArithmeticException();//主动抛出异常
        }
    }
}
